package com.example.smartf.controller.root;

import com.example.smartf.model.mongo.Group;
import com.example.smartf.service.RootService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *关于Root用户的操作管理---对组内用户和设备的管理
 * 表现在MongoDB中的Group表中
 */


@Api("Root权限管理")
@CrossOrigin(origins = "*")
@RestController
public class RootController {

    @Autowired
    private RootService rootService;


    //root 用户添加一个新的设备(连接测试)
    @ApiOperation("root用户添加一个新的设备(连接测试)")
    @ApiImplicitParam(name = "deviceID", value = "一个新的设备的ID", dataType = "String",paramType = "query")
    @PostMapping(value = "/root/newdevtest")
    public String newdevtest(@RequestParam("deviceID") String deviceID){
        return rootService.newdevtest(deviceID);
    }

    //root 用户添加一个新的设备
    @ApiOperation("root用户添加一个新的设备")
    @ApiImplicitParam(name = "deviceID", value = "一个新的设备的ID", dataType = "String",paramType = "query")
    @PostMapping(value = "/root/adddev")
    public String addnewdev(@RequestParam("deviceID") String deviceID){
        return rootService.addnewdev(deviceID);
    }



    //root 用户添加一个新的组
    @ApiOperation("root用户添加一个新的组")
    @ApiImplicitParam(name = "groupID", value = "一个新的组ID", dataType = "String",paramType = "query")
    @PostMapping(value = "/root/addgroup")
    public String addgroup(@RequestParam("groupID") String groupID){
        return rootService.addnewgroup(groupID);
    }

    //root 用户删除一个分组
    @ApiOperation("root用户删除一个分组")
    @ApiImplicitParam(name = "groupID", value = "组ID", dataType = "String",paramType = "query")
    @PostMapping(value = "/root/delgroup")
    public String delgroup(@RequestParam("groupID") String groupID){
        return rootService.delgroup(groupID);
    }

    //root 用户展示所有分组
    @ApiOperation("root展示所有分组")
    @GetMapping(value = "/root/showgroup")
    public List<Group> showgroup(){
        return rootService.showgroup();
    }

    //root用户给一个分组加用户
    @ApiOperation("root用户给分组加一个用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupID",value = "指定组ID",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "username",value = "加入的用户名",dataType = "String",paramType = "query")
    })
    @PostMapping(value = "/root/adduseringroup")
    public String adduser(@RequestParam("groupID") String groupID,
                          @RequestParam("username") String username){
        return rootService.adduser(groupID,username);
    }



    //root用户给一个分组删除用户
    @ApiOperation("root用户给分组删除一个用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupID",value = "指定组ID",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "username",value = "删除的用户名",dataType = "String",paramType = "query")
    })
    @PostMapping(value = "/root/deluseringroup")
    public String deluser(@RequestParam("groupID") String groupID,
                          @RequestParam("username") String username){
        return rootService.deluser(groupID,username);
    }



    //root用户给一个分组加设备
    @ApiOperation("root用户给分组加一个设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupID",value = "指定组ID",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "deviceID",value = "添加的设备名",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "kind",value = "设备种植作物种类",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "devicename",value = "设备名称",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "remarks",value = "设备备注",dataType = "String",paramType = "query")
    })
    @PostMapping(value = "/root/adddevingroup")
    public String adddevice(@RequestParam("groupID") String groupID,
                            @RequestParam("deviceID") String deviceID,
                            @RequestParam("kind") String kind,
                            @RequestParam("devicename") String devicename,
                            @RequestParam("remarks") String remarks){
        return rootService.adddevice(groupID,deviceID,kind,devicename,remarks);
    }



    //root用户给一个分组删除设备
    @ApiOperation("root用户给分组删除一个设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupID",value = "指定组ID",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "deviceID",value = "删除的设备名",dataType = "String",paramType = "query")
    })
    @PostMapping(value = "/root/deldevingroup")
    public String deldevcie(@RequestParam("groupID") String groupID,
                            @RequestParam("deviceID") String deviceID){
        return rootService.deldevcie(groupID,deviceID);
    }

}
